package slidePlay;


import javafx.scene.image.Image;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class PlayList {
    public static LinkedList<Image> imagesList = new LinkedList<>();
    public static LinkedList<Image> allImage = new LinkedList<>();
    public static boolean isLoad = false;
    public static int playIndex = 0;  //图片查看界面当前显示图片
    public static int slidePlayIndex = 0;  //幻灯片播放界面当前显示图片
    public static int listLength = 0;  //链表长度
    public static double waitTime = 0;  //幻灯片播放等待时间
    public static int playNum = 0;   //幻灯片播放图片序号 对应链表

    public static void reset() {
        playIndex = 0;
        waitTime = 0;
        playNum = 0;
    }

    public static String getName(int index) {
        String url = imagesList.get(index).getUrl();
        String name;
        int temp = url.lastIndexOf("\\");
        name = url.substring(temp + 1);
        return name;
    }

    //更新播放列表数据
    public static void refresh() {
        listLength = imagesList.size();
    }

    public PlayList() {
    }

    public static void addPlayList(Image newImage) {
        allImage.addLast(newImage);
        System.out.println("!!!!!!!!!" + allImage.getLast().getUrl());
        // refresh();
    }

    //初始化链表
    public static void initList(List<File> arrayListImageViewChoice) {
        imagesList.clear();
        reset();
        for (File file : arrayListImageViewChoice) {
            addPlayList(new Image(("file:" + file.getAbsolutePath()), 5000, 5000, true, true, true));
            // addPlayList(new Image(("file:"+file.getAbsolutePath())));
        }
    }

    public static void initList(List<File> arrayListImageViewChoice, ArrayList<Integer> point) {
        imagesList.clear();
        reset();
        if (!isLoad) {
            allImage.clear();
            for (File file : arrayListImageViewChoice) {
                addPlayList(new Image(("file:" + file.getAbsolutePath()), 3000, 4000, true, true, true));
            }
            System.out.println("!!!!!!!!!");
            isLoad = true;
        }
        if (point.isEmpty() || point.size() == 1) {
            if (!point.isEmpty()) {
                playIndex = point.get(0);
            }
            imagesList.removeAll(imagesList);
            imagesList.addAll(allImage);
            //  imagesList.add(allImage);
            System.out.println("point empty");
        } else {
            playIndex = 0;
            imagesList.clear();
            for (int i = 0; i < point.size(); i++) {
                imagesList.addLast(allImage.get(point.get(i)));
                System.out.println("point[i]=" + point.get(i));
            }

        }
        refresh();
    }

    public static boolean isIsLoad() {
        return isLoad;
    }

    public static void setIsLoad(boolean isLoad) {
        PlayList.isLoad = isLoad;
    }
}
